<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="账号">
        <el-input v-model="userName" placeholder="请输入账号"></el-input>
      </el-form-item>


      <el-form-item label="密码">
        <el-input v-model="password" placeholder="请输入密码" type="password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  name: 'Login',
  data() {
    return {
      userName: 'zhangsan',
      password: '123456'
    }
  },
  methods: {
    onSubmit() {
      // {
      //   "account": "zhangsan", //账户名
      //     "password": "123456" //密码
      // }
      const loginObj = {
        account: this.userName,
        password: this.password
      }
      console.log(loginObj)
      request.post("/user/login", loginObj)
          .then(res => {
          if(res.code === 200){
            console.log(res.msg)
            localStorage.setItem("token",res.data.token)
            this.$message.success('登录成功');
            this.$router.push("/ProductManagement")
          //  跳转到首页
          }else {
            console.log(res.msg)
          }
          })
    }
  }
}
</script>
